<?php

namespace App\Http\Controllers\Miniapp;

use App\Http\Controllers\MiniappController;
use App\Models\miniapp\Order;

class OrderController extends MiniappController
{

    public function index()
    {
        $page = request('page', 1);
        $limit = request('limit', 10);

        $list = Order::with('goods:id,title,image,description')
            ->select('id', 'goods_id', 'tradeNo', 'title', 'status', 'pay_at', 'created_at')
            ->where('user_id', $this->uid)
            ->latest();

        $data = $this->getPaginate($list, $page, $limit);
        return $this->successful($data);
    }

    public function show($id)
    {
        $order = Order::where(compact('id'))
            ->where('user_id', $this->uid)
            ->with('goods:id,title,image,description')
            ->first();

        if (!$order) return $this->fail('订单不存在或已删除');

        return $this->successful($order);
    }
}
